package com.hydra.framework.event.core;

import com.hydra.framework.util.StringUtil;

/**
 * Created by Hydra.
 * 保证在一个dispatcher内的action唯一
 */
public class EventAction {

    private final Object mAction;
    /**
     * 事件的类型
     */
    private final boolean mIsSticky;

    public EventAction(Object action) {
        this(action, false);
    }

    public EventAction(Object action, boolean isSticky) {
        mAction = action;
        mIsSticky = isSticky;
    }

    @SuppressWarnings("unchecked")
    public <T> T getAction() {
        return (T) mAction;
    }

    public boolean isSticky() {
        return mIsSticky;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        return getAction().equals(((EventAction) o).getAction());
    }

    @Override
    public String toString() {
        return StringUtil.combineStr(getClass(), "-", mIsSticky, "-", mAction);
    }

    @Override
    public int hashCode() {
        return toString().hashCode();
    }
}
